package cn.fu.security.hmac;

import org.bouncycastle.crypto.digests.MD5Digest;
import org.bouncycastle.crypto.macs.HMac;
import org.bouncycastle.crypto.params.KeyParameter;

/**
 * @Title: MyMac.java
 * @Package cn.fu.security.mac
 * @Description: 包涵密钥的消息摘要算法
 * @author zhangxiaofu
 * @Company www.viewhigh.com
 * @date 2016年8月21日 上午2:03:25
 * @version V1.0
 */
public class MyHmac {

	private static String src = "99fu";

	public static void main(String[] args) {
		bcHmacMD5();

	}

	public static void bcHmacMD5() {
		HMac hMac = new HMac(new MD5Digest());
		hMac.init(new KeyParameter(org.bouncycastle.util.encoders.Hex.decode("aaaaaaaa")));
		hMac.update(src.getBytes(), 0, src.getBytes().length);
		byte[] hmacMD5Bytes = new byte[hMac.getMacSize()];// 执行摘要
		hMac.doFinal(hmacMD5Bytes, 0);

		System.err.println("bcHmacMD5:" + org.bouncycastle.util.encoders.Hex.toHexString(hmacMD5Bytes));
	}
}
